

#include "ntc.h"

#include <Thermistor.h>
#include <NTC_Thermistor.h>

#define SENSOR_PIN              1
#define REFERENCE_RESISTANCE    10000
#define NOMINAL_RESISTANCE      10000
#define NOMINAL_TEMPERATURE     25
#define B_VALUE                 3950
#define ESP32_ANALOG_RESOLUTION 4095
#define ESP32_ADC_VREF_MV       3300

Thermistor* thermistor;

void setupNTC(){

 thermistor = new NTC_Thermistor_ESP32(
    SENSOR_PIN,
    REFERENCE_RESISTANCE,
    NOMINAL_RESISTANCE,
    NOMINAL_TEMPERATURE,
    B_VALUE,
    ESP32_ADC_VREF_MV,
    ESP32_ANALOG_RESOLUTION
  );


}

float readNTC(){
    if(thermistor==nullptr){
        return 0.0f;
    }

    float t = thermistor->readCelsius()-2;
    return t;
}

String readNTCStr(){
    float ntcValue = readNTC();
    String ntcStr(ntcValue);
     int dotIndex= ntcStr.indexOf(".");
   return  ntcStr.substring(0,dotIndex+2);
}